package com.ssyc.common.manager;

import android.support.v4.app.FragmentManager;
import android.view.Gravity;

import com.ssyc.common.R;
import com.timmy.tdialog.TDialog;
import com.timmy.tdialog.listener.OnBindViewListener;
import com.timmy.tdialog.listener.OnViewClickListener;

/**
 * TDialgo的管理类
 * Created by Administrator on 2018/12/11 0011.
 */

public class TDialogManager {

    public static TDialog tDialog;

    /**
     * 显示TDiaglog的方法
     *
     * @param fragmentManager    管理器对象
     * @param resId              布局Id
     * @param onBindViewListener 绑定视图的解耦
     * @param clickListener      点击事件接口
     * @param ids                需要绑定的控件的id
     */
    public static void show(FragmentManager fragmentManager, int resId, float level, OnBindViewListener onBindViewListener, OnViewClickListener clickListener, int... ids) {
        //防止对象创建过多
        if (tDialog != null) {
            tDialog = null;
        }

        tDialog = new TDialog.Builder(fragmentManager)
                .setLayoutRes(resId)
                .setGravity(Gravity.CENTER)
                .setDimAmount(level)
                .setCancelableOutside(true)
                .addOnClickListener(ids)
                .setOnBindViewListener(onBindViewListener)
                .setOnViewClickListener(clickListener)
                .setDialogAnimationRes(R.style.common_pop_anim_style)
                .create();

        tDialog.show();
    }

    /**
     * 关闭Dialog的方法
     */
    public static void dismiss() {
        if (null != tDialog) {
            tDialog.dismiss();
        }
    }


}
